package com.xpec.c4.codec.h2o;

import java.nio.ByteBuffer;

import com.xpec.c4.codec.Codec;

public class H2oCodec implements Codec {

	public H2oCodec() {

	}

	/**
	 * 注册类和枚举
	 *
	 *  @param clz
	 *  @throws Exception
	 */
	public void registClass(Class<?> clz) throws Exception {
		CodedInfo.registClass(clz);
	}

	/**
	 * 缓存所有注册过的类的字段。
	 *
	 *  @throws Exception
	 */
	public void registerFields() throws Exception {
		CodedInfo.registerFields();
	}

	@Override
	public ByteBuffer encode(Object obj) throws Exception {
		return H2oEncoder.encodeToBuffer(obj);
	}

	@Override
	public byte[] encodeEx(Object obj) throws Exception {
		return H2oEncoder.encodeToBytes(obj);
	}

	@Override
	public Object decode(ByteBuffer byteBuffer) throws Exception {
		return H2oDecoder.decode(byteBuffer);
	}

	@Override
	public byte[] encodeByte(Object obj) throws Exception {
		return H2oEncoder.encodeToBytes(obj);
	}

	@Override
	public Object decodeByte(byte[] byteBuffer) throws Exception {
		return H2oDecoder.decode(byteBuffer);
	}

}
